package cn.exlu.coco.core.server.email.test;

import java.io.File;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import cn.exlu.coco.core.server.email.EmailConnection;
import cn.exlu.coco.core.server.email.EmailService;
import cn.exlu.coco.core.server.email.EmailTransport;
import cn.exlu.coco.core.server.email.FileEmail;
import cn.exlu.coco.core.server.email.LoginAuthentication;

public class SendFileMessage {

    public static void main(String[] args) throws AddressException, MessagingException {
        EmailService service = new EmailService();
        service.setSmtpAddress("smtp.126.com");
        service.setAuth(true);
        LoginAuthentication loginAuth = new LoginAuthentication("testlogin123@126.com",
            "testlogin1");
        FileEmail te = new FileEmail();
        te.setSendFrom("testlogin123@126.com");
        te.setSendTo("836612962@qq.com");
        te.setSubject("你好");
        te.setText("Hello this is first text email");
        te.setFile(new File("D:/MyTemp/JavaBean.xlsm"));
        EmailConnection ec = service.createEmailConnection(loginAuth);
        EmailTransport et = ec.createEmailTransport("smtp");
        et.send(te);
        te.setText("Hello");
        et.send(te);
        et.close();


        System.out.println("Success");

    }

}
